﻿
using DefenseQuestion;
using Microsoft.EntityFrameworkCore;
using System;
using System.Diagnostics.CodeAnalysis;

namespace BRbacSystem.Repositorys
{
    public class DefenseQuestionDbContext : DbContext
    {
        public DefenseQuestionDbContext([NotNullAttribute] DbContextOptions options) : base(options)
        {

        }
        /// <summary>
        /// 答题记录表
        /// </summary>
        public DbSet<Answer> Answer { get; set; }
        /// <summary>
        /// 出题表
        /// </summary>
        public DbSet<Exam> Exam { get; set; }
        /// <summary>
        /// 班级表
        /// </summary>
        public DbSet<Grade> Grade { get; set; }
        /// <summary>
        /// Menu
        /// </summary>
        public DbSet<Menu> Menu { get; set; }
        /// <summary>
        /// 项目经理表
        /// </summary>
        public DbSet<ProjectManager> ProjectManager { get; set; }
        /// <summary>
        /// 题库表
        /// </summary>
        public DbSet<Question> Question { get; set; }
        /// <summary>
        /// 题型分类表
        /// </summary>
        public DbSet<QuestionType> QuestionType { get; set; }
        /// <summary>
        /// 学生表
        /// </summary>
        public DbSet<Student> Student { get; set; }
        /// <summary>
        /// 技术分类表
        /// </summary>
        public DbSet<TechType> TechType { get; set; }
        /// <summary>
        /// 用户表
        /// </summary>
        public DbSet<User> User { get; set; }
        /// <summary>
        /// 用户类型表
        /// </summary>
        public DbSet<User_UserType> User_UserType { get; set; }
        /// <summary>
        /// 用户类型表
        /// </summary>
        public DbSet<UserType> UserType { get; set; }
        /// <summary>
        /// 用户类型菜单表
        /// </summary>
        public DbSet<UserType_Menu> UserType_Menu { get; set; }


        //设置字段约束
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Answer>(build =>
            {
                build.Property(x => x.FullName).HasMaxLength(50).IsRequired();
                build.Property(x => x.StudentCode).HasMaxLength(50).IsRequired();
                build.Property(x => x.AnswerConten).HasMaxLength(500);
                build.Property(x => x.Comment).HasMaxLength(500);
            });

            modelBuilder.Entity<Grade>(build =>
            {
                build.Property(x => x.GradeName).HasMaxLength(50).IsRequired();
            });

            modelBuilder.Entity<Menu>(build =>
            {
                build.Property(x => x.MenuName).HasMaxLength(50).IsRequired();
                build.Property(x => x.MenuRoute).HasMaxLength(300).IsRequired();
            });

            modelBuilder.Entity<ProjectManager>(build =>
            {
                build.Property(x => x.WorkCode).HasMaxLength(50).IsRequired();

            });

            modelBuilder.Entity<Question>(build =>
            {
                build.Property(x => x.QuestionName).HasMaxLength(50).IsRequired();
            });

            modelBuilder.Entity<QuestionType>(build =>
            {
                build.Property(x => x.QuestionTypeName).HasMaxLength(50).IsRequired();
            });

            modelBuilder.Entity<Student>(build =>
            {
                build.Property(x => x.StudentCode).HasMaxLength(50).IsRequired();
            });

            modelBuilder.Entity<TechType>(build =>
            {
                build.Property(x => x.TypeName).HasMaxLength(50).IsRequired();
            });

            modelBuilder.Entity<User>(build =>
            {
                build.Property(x => x.Mobile).HasMaxLength(30).IsRequired();
                build.Property(x => x.Account).HasMaxLength(30).IsRequired();
                build.Property(x => x.Avatar).HasMaxLength(300).IsRequired();
                build.Property(x => x.Email).HasMaxLength(50).IsRequired();
                build.Property(x => x.FullName).HasMaxLength(30).IsRequired();
                build.Property(x => x.OpenId).HasMaxLength(300).IsRequired();
                build.Property(x => x.Password).HasMaxLength(100).IsRequired();
            });

            modelBuilder.Entity<UserType>(build =>
            {
                build.Property(x => x.UserTypeName).HasMaxLength(30).IsRequired();
            });

            base.OnModelCreating(modelBuilder);
        }
    }
}
